//
//  WCG_N_TableViewCell.m
//  Project_B
//
//  Created by 黑黑 on 15/11/24.
//  Copyright © 2015年 Atom_Wang. All rights reserved.
//

#import "WCG_N_TableViewCell.h"     // 第一页cell

#import "NSString+GXSizeWithText.h" // 自适应尺寸
#import "UIImageView+GXCircleImageView.h" //``裁切圆形图片方法
#import "FontManager.h"             // 字体管理器
#import "GXProviderDataModel.h"     // 第一页model
#import "UIImageView+WebCache.h"    // 网络图片
#import "UIImage+GIF.h"             // 动图效果

//cell 120

//左边界
#define kProviderCellLeftBorder 20
//上边界
#define kProviderCellTopBorder 25

//图片边长
#define kProviderCellImageViewSize 55

//标题与图片的距离
#define kProviderCellLabelLeftBorder 20
//简介与标题的距离
#define kProviderCellDescLabelTopBorder 5
//----------------

//标题字号
#define kProviderTitleLabelFontSize 20
//简介字号
#define kProviderDescLabelFontSize 14

//名字高度
#define kProviderNameLabelHeight 30

@interface WCG_N_TableViewCell ()
@property (nonatomic, retain) UIImageView *providerImageView; // 图片
@property (nonatomic, retain) UILabel *providerNameLabel;     // 名字
@property (nonatomic, retain) UILabel *providerDescLabel;     // 简介
@end

@implementation WCG_N_TableViewCell

#pragma mark >>> 初始化子控件
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 创建子控件
        [self createSubViews];
    }
    return self;
}

#pragma mark >>> 创建子控件

- (void)createSubViews {
    
    // 图片
    self.providerImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.providerImageView];
    
    // 名字
    self.providerNameLabel = [[UILabel alloc] init];
    [self.providerNameLabel setFont:[UIFont systemFontOfSize:kProviderTitleLabelFontSize]];
    self.providerNameLabel.textColor = [UIColor blackColor];
    [self.contentView addSubview:self.providerNameLabel];
    
    // 简介
    self.providerDescLabel = [[UILabel alloc] init];
    [self.providerDescLabel setFont:[UIFont systemFontOfSize:kProviderDescLabelFontSize]];
    self.providerDescLabel.textColor = [UIColor colorWithRed:117.f / 255 green:149.f /  255 blue:174.f / 255  alpha:1.0];
    [self.providerDescLabel setNumberOfLines:0];
    [self.contentView addSubview:self.providerDescLabel];
}

#pragma mark >>> 布局设置

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    // 图片
    [self.providerImageView setCircleImageViewFrame:CGRectMake(kProviderCellLeftBorder, kProviderCellTopBorder, kProviderCellImageViewSize, kProviderCellImageViewSize)];
    
    // 名字
    CGFloat nameLabelX = CGRectGetMaxX(self.providerImageView.frame) + kProviderCellLabelLeftBorder;
    CGFloat nameLabelW = self.contentView.frame.size.width - nameLabelX - 3.5/2.0 * kProviderCellLeftBorder;
    [self.providerNameLabel setFrame:CGRectMake(nameLabelX, kProviderCellTopBorder, nameLabelW, kProviderNameLabelHeight)];
    
    // 简介
    CGRect descLabelSize = [self.providerDescLabel.text SizeWithTextFontSize:kProviderDescLabelFontSize textWidth:nameLabelW];
    descLabelSize.size.height = descLabelSize.size.height > 50 ? 50:descLabelSize.size.height;
    CGFloat descLabelY = CGRectGetMaxY(self.providerNameLabel.frame) + kProviderCellDescLabelTopBorder;
    [self.providerDescLabel setFrame:CGRectMake(nameLabelX, descLabelY, nameLabelW, descLabelSize.size.height)];
}

#pragma mark >>> 赋值

- (void)setProviderModel:(GXProviderDataModel *)providerModel{
    
    if (_providerModel != providerModel) {
        _providerModel  = providerModel;
    }
    // 图片
    [self.providerImageView sd_setImageWithURL:_providerModel.avatar placeholderImage:[UIImage sd_animatedGIFNamed:@"loading"]];
    // 姓名
    [self.providerNameLabel setText:_providerModel.screen_name];
    // 简介
    [self.providerDescLabel setText:_providerModel.provider_description];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
